﻿// Decompiled with JetBrains decompiler
// Type: NetickEditor.NetworkTransformEditor
// Assembly: Netick.Unity.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 0658BB4A-05C4-428D-9BD6-82E94959F5A1
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Editor\Netick.Unity.Editor.dll

using Netick.Unity;
using System;
using UnityEditor;
using UnityEngine;

#nullable disable
namespace NetickEditor;

[CustomEditor(typeof (NetworkTransform), true)]
[CanEditMultipleObjects]
public class NetworkTransformEditor : Editor
{
  private SerializedProperty PrecisionProperty;
  private SerializedProperty RenderTransformProperty;
  private SerializedProperty InterpolationModeProperty;
  private SerializedProperty SettingProperty;
  private SerializedProperty TransformSpaceProperty;
  private SerializedProperty TeleportDistanceProperty;
  private SerializedProperty UseForAOIPositionProperty;
  private SerializedProperty ErrorCorrectionEnableProperty;
  private SerializedProperty ErrorCorrectionProperty1;
  private SerializedProperty ErrorCorrectionProperty2;
  private const string RenderTransformTooltip = "The interpolated transform. \n\nWith Netick, you should divide your object into two parts:\n\n1. The Simulation Game Object: which is the raw non-interpolated part - containing any colliders or simulation-related components.\n\n2. The View Game Object: which is the interpolated/smoothed part - containing any mesh renderers or view-related components.\n\nThe view game object must be a child of the simulation object.";
  private const string InterpolationModeTooltip = "Choose the source of the interpolation data.";
  private const string SettingsTooltip = "Replication settings.";
  private const string TeleportDistanceTooltip = "The distance required between the positions of snapshots to affect a teleportation in the interpolated/smoothed position of Render Transform.";
  private const string PrecisionTooltip = "The precision of the position compression.";
  private const string UseForAOIPositionTooltip = "Choose whether or not you want the position of this transform to be used for the AoI position of the network object this script is attached to.";
  private const string CorrectionMultiplierTooltip = "Controls the rate at which the prediction error will be corrected.";

  private void OnEnable()
  {
    this.TeleportDistanceProperty = this.serializedObject.FindProperty("TeleportDistance");
    this.RenderTransformProperty = this.serializedObject.FindProperty("RenderTransform");
    this.InterpolationModeProperty = this.serializedObject.FindProperty("_interpolationSource");
    this.PrecisionProperty = this.serializedObject.FindProperty("PositionPrecision");
    this.SettingProperty = this.serializedObject.FindProperty("Settings");
    this.TransformSpaceProperty = this.serializedObject.FindProperty("TransformSpace");
    this.UseForAOIPositionProperty = this.serializedObject.FindProperty("UseForAOIPosition");
    this.ErrorCorrectionEnableProperty = this.serializedObject.FindProperty("EnablePredictionErrorCorrectionSmoothing");
    this.ErrorCorrectionProperty1 = this.serializedObject.FindProperty("CorrectionMultiplier");
    this.ErrorCorrectionProperty2 = this.serializedObject.FindProperty("TeleportErrorThreshold");
  }

  public virtual void OnInspectorGUI()
  {
    this.serializedObject.Update();
    NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.RenderTransformProperty, "The interpolated transform. \n\nWith Netick, you should divide your object into two parts:\n\n1. The Simulation Game Object: which is the raw non-interpolated part - containing any colliders or simulation-related components.\n\n2. The View Game Object: which is the interpolated/smoothed part - containing any mesh renderers or view-related components.\n\nThe view game object must be a child of the simulation object.");
    EditorGUI.BeginDisabledGroup(Application.isPlaying);
    NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.SettingProperty, "Replication settings.");
    EditorGUI.EndDisabledGroup();
    NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.InterpolationModeProperty, "Choose the source of the interpolation data.");
    NetickEditorToggleState.ShowAdvancedNetworkTransform = EditorGUILayout.BeginFoldoutHeaderGroup(NetickEditorToggleState.ShowAdvancedNetworkTransform, "Advanced", (GUIStyle) null, (Action<Rect>) null, (GUIStyle) null);
    if (NetickEditorToggleState.ShowAdvancedNetworkTransform)
    {
      EditorGUI.BeginDisabledGroup(Application.isPlaying);
      NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.TransformSpaceProperty, "Space used in replicating position and rotation of the transform.");
      NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.TeleportDistanceProperty, "The distance required between the positions of snapshots to affect a teleportation in the interpolated/smoothed position of Render Transform.");
      NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.UseForAOIPositionProperty, "Choose whether or not you want the position of this transform to be used for the AoI position of the network object this script is attached to.");
      NetickEditorProperty.DrawIntSlider(this.serializedObject.targetObject, this.PrecisionProperty, "Precision", 5, 1, "The precision of the position compression.");
      EditorGUILayout.LabelField((1f / Mathf.Pow(10f, (float) this.PrecisionProperty.intValue)).ToString("F99").TrimEnd('0'), Array.Empty<GUILayoutOption>());
      EditorGUI.EndDisabledGroup();
    }
    EditorGUILayout.EndFoldoutHeaderGroup();
    if (NetickEditorToggleState.ShowAdvancedNetworkTransform)
    {
      NetickEditorToggleState.ShowAdvancedErrorSmoothingNetworkTransform = EditorGUILayout.BeginFoldoutHeaderGroup(NetickEditorToggleState.ShowAdvancedErrorSmoothingNetworkTransform, "Prediction Error Correction Smoothing", (GUIStyle) null, (Action<Rect>) null, (GUIStyle) null);
      if (NetickEditorToggleState.ShowAdvancedErrorSmoothingNetworkTransform)
      {
        EditorGUI.BeginDisabledGroup(Application.isPlaying);
        NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, "Enable", this.ErrorCorrectionEnableProperty);
        EditorGUI.EndDisabledGroup();
        NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.ErrorCorrectionProperty1, "Controls the rate at which the prediction error will be corrected.");
        NetickEditorProperty.DrawProperty(this.serializedObject.targetObject, this.ErrorCorrectionProperty2);
      }
    }
    this.serializedObject.ApplyModifiedProperties();
  }
}
